<template>
    <div>
      <!--      面包屑导航-->
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>订单管理</el-breadcrumb-item>
        <el-breadcrumb-item>订单列表</el-breadcrumb-item>
      </el-breadcrumb>
      <!--  卡片视图区域-->
      <el-card class="box-card">

        <!--      搜索区域-->
        <el-row :gutter="20">
          <el-col :span="8">
            <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable
                      @clear="getOrdersList" @change="getOrdersList" >
              <el-button slot="append" icon="el-icon-search" @click="getOrdersList"></el-button>
            </el-input>
          </el-col>
        </el-row>

        <!--        用户列表区-->
        <el-table :data="orderList" border stripe>
          <!--          索引列-->
          <el-table-column type="index"></el-table-column>
          <el-table-column prop="order_number" label="订单编号" width="360px"></el-table-column>
          <el-table-column prop="order_price" label="订单价格"></el-table-column>
          <el-table-column prop="order_pay" label="是否付款">
            <template scope="scope">
              <el-tag type="success" v-if="scope.row.order_pay === '1'">已付款</el-tag>
              <el-tag type="danger" v-else>未付款</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="is_send" label="是否发货"></el-table-column>
          <el-table-column prop="create_time" label="下单时间" >
            <template scope="scope">
              {{scope.row.create_time | dataFormate}}
            </template>
          </el-table-column>
          <el-table-column label="操作" width="130px">
            <!--            作用域插槽-->
            <template slot-scope="scope">
              <!--             修改地址按钮-->
              <!--              open-delay延迟出现，单位毫秒 enterable 鼠标是否可进入到 tooltip 中-->
              <el-tooltip effect="dark" content="修改订单地址" placement="top" :open-delay=openDelay :enterable="false">
                <el-button type="primary" icon="el-icon-edit" size="mini" @click="showEdit"></el-button>
              </el-tooltip>
              <!--              展示物流按钮-->
              <el-tooltip effect="dark" content="物流信息" placement="top" :open-delay=openDelay :enterable="false">
                <el-button type="success" icon="el-icon-location" size="mini" @click="showMeil"></el-button>
              </el-tooltip>
            </template>
          </el-table-column>
        </el-table>

        <!--      分页区域-->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[2, 5, 10]"
          :page-size="queryInfo.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          background>
        </el-pagination>

        <!--      修改订单地址弹框-->
        <el-dialog
          title="修改订单地址"
          :visible.sync="editDialogVisible"
          width="50%"
          @close="resetForm('editFormRef')">
          <el-form :model="editForm" ref="editFormRef" label-width="100px">
            <el-form-item label="省市区/县" prop="address1">
              <!--            级联选择框 options: 数据源 props: 配置选项 v-model绑定的是选中的数据，必须是一个数组-->
              <el-cascader
                v-model="selectKeys"
                :options="cityData"
                :props="cateProps"
                clearable>
              </el-cascader>
            </el-form-item>
            <el-form-item label="详细地址" prop="address2">
              <el-input v-model="editForm.address2"></el-input>
            </el-form-item>
          </el-form>
          <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary">确 定</el-button>
        <el-button type="info" @click="resetForm('editFormRef')">重置</el-button>
        </span>
        </el-dialog>

        <!--      物流信息弹框-->
        <el-dialog
          title="物流信息"
          :visible.sync="mailDialogVisible"
          width="50%">
<!--            物流步骤条-->
          <el-timeline>
            <el-timeline-item
              v-for="(activity, index) in mailForm"
              :key="index"
              :timestamp="activity.time">
              {{activity.context}}
            </el-timeline-item>
          </el-timeline>
          <span slot="footer" class="dialog-footer">
          <el-button @click="mailDialogVisible = false">确 定</el-button>
          </span>
        </el-dialog>

      </el-card>
    </div>
</template>

<style scoped>
    body {
        background-color: #ff0000;
    }
</style>

<script>
// 导入城市数据
import cityData from './citydata'

export default {
  data () {
    return {
      // 订单列表数据
      orderList: [],
      // 获取订单列表的参数对象
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 5,
        user_id: '',
        pay_status: '',
        is_send: '',
        order_fapiao_title: '',
        order_fapiao_company: '',
        order_fapiao_content: '',
        consignee_addr: ''
      },
      total: 0,
      openDelay: 500,
      // 修改订单地址表单
      editForm: {
        address1: '',
        address2: ''
      },
      // 修改订单地址开关
      editDialogVisible: false,
      // 修改订单验证规则
      editRules: {
        address1: [
          {
            required: true,
            message: '请选中省市区县',
            trigger: 'blur'
          }
        ],
        address2: [
          {
            required: true,
            message: '请输入详细地址',
            trigger: 'blur'
          }
        ]
      },
      cityData,
      cateProps: {
        value: 'value',
        label: 'label',
        children: 'children',
        checkStrictly: true,
        // 触发方式，默认点击触发，hover鼠标移上去即可触发
        expandTrigger: 'hover'
      },
      // 选中的父级id数组
      selectKeys: [],
      // 物流弹窗开关
      mailDialogVisible: false,
      // 物流信息表单
      mailForm: []
    }
  },
  methods: {
    async getOrdersList () {
      const { data: res } = await this.$http.get('orders', { params: this.queryInfo })
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      console.log(res.data)
      this.orderList = res.data.goods
      this.total = res.data.total
    },
    //  监听pageSize改变事件
    handleSizeChange (newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrdersList()
    },
    //  监听页码值改变事件
    handleCurrentChange (newPage) {
      this.queryInfo.pagenum = newPage
      this.getOrdersList()
    },
    // 表单重置功能
    resetForm (formName) {
      this.$refs[formName].resetFields()
    },
    // 修改订单地址
    showEdit() {
      this.editDialogVisible = true
    },
    // 展示物流弹框
    async showMeil() {
      const { data: res } = await this.$http.get('/kuaidi/1106975712662')
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.mailForm = res.data
      this.mailDialogVisible = true
      console.log(this.mailForm)
    }
  },
  created () {
    this.getOrdersList()
  }
}
</script>
